var express=require('express')
var Router=express.Router()
var db=require('../../tools/database/index.js')

//存储头像
var savImg=require('./SaveImg.js')

//解析post 数据
var PostData=require('../../tools/PostData/index.js')
Router.post('/admin/business',async (req,res)=>{
	var data=await PostData(req);
	var query={name:data.name};
	var client=await db.merchants.hasUser(query);
	if(client){
		res.send({
			state:404,
			msg:'用户已存请更换用户名'
		})
		return;
	}
	var HeadImg=await savImg(data.HeadImg,`${data.name}-${data._id}`)
	var result =await db.merchants.append({
			"_id":Date.now(),
			name:data.name,
			password:data.password,
			HeadImg:HeadImg.url,
			StoreName:data.StoreName
	})
	res.send({
		state:200,
		msg:'注册成功！',
	})
})

 module.exports=Router